/*  This file is part of the KITT project
    Purpose: This file provides functions to retrieve sensor information from the arduino.
    Functions:
    Arduino(int port)-Initializes serial port of arduino.
    ArdGetHeading()-Gets heading from digital compass.
    ArdGetSpeed()-Gets from hall effect sensor.
    ArdGetDistance()-Gets the distance from hall effect sensor.

    Program Depends on:
    kittrs232-These files provide a set of serial functions for the KITT devices.
*/
#include "kittrs232.h"
#include "Arduino.h"

Arduino::Arduino(int port) {
    this->Ardport = port;//This number indicates the port number being used.  In this case port this->port represents tty/USB1, the second usb serial port.
    OpenComport(Ardport,9600,C8n1);
}

int Arduino::ArdGetHeading(){
    char buffer[256];
    int heading;
    cprintf(Ardport,"H");
    usleep(100000);
    PollComportUntil(Ardport,buffer,'\r');
    sscanf(buffer,"%n",&heading);
    return heading;
}
float Arduino::ArdGetSpeed(){
    char buffer[256];
    float speed;
    cprintf(Ardport,"S");
    usleep(100000);
    PollComportUntil(Ardport,buffer,'\r');
    sscanf(buffer,"%f",&speed);
    return speed;
}
float Arduino::ArdGetDistance(){
    char buffer[256];
    float distance;
    cprintf(Ardport,"S");
    usleep(100000);
    PollComportUntil(Ardport,buffer,'\r');
    sscanf(buffer,"%f",&distance);
    return distance;
}
